package com.zeng.user.web.controller;

import com.zeng.user.domain.User;
import com.zeng.user.service.UserService;
import com.zeng.webmvc.controller.RestController;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.io.IOException;

/**
 * @author zyb
 * @date 2021-03-02 23:05
 */
public class RegisterController implements RestController {

    @Resource(name = "bean/UserService")
    private UserService userService;


    @Path("/register")
    @POST
    public void register(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String email = request.getParameter("email");
        String password = request.getParameter("password");
        User user = new User();
        user.setPassword(password);
        user.setEmail(email);
        boolean register = userService.register(user);
        if (register) {
            request.getRequestDispatcher("/success").forward(request, response);
        }
    }
}
